package com.gitee.wsl.ext.array

import com.gitee.wsl.ext.list.partition


fun <T> Array<T>.partition(k: Int, cmp: (T, T) -> Int) = partition(indices, k, cmp)

fun <T> Array<T>.partition(rng: IntRange, k: Int, cmp: (T, T) -> Int) {
    partition(
        this,
        rng.first,
        rng.last,
        k,
        { get(it) },
        cmp,
        { a, b -> this[a] = this[b].also { this[b] = this[a] } }
    )
}